package cn.com.guage.dynamic.datasource.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.guage.dynamic.datasource.domain.Blog;
import cn.com.guage.dynamic.datasource.domain.User;
import cn.com.guage.dynamic.datasource.service.IBlogService;
import cn.com.guage.dynamic.datasource.service.IUserService;

/**
 * 代码生成 操作处理
 * 
 * 
 */
@Controller
@RequestMapping("/test")
public class TestController
{
	
	

    @Autowired
    private IUserService userService;
    @Autowired
    private IBlogService blogService;

    @GetMapping("/getDb1")
    @ResponseBody
    public User getDb1()
    {
    	return userService.selectUserById(1);
    }
    @GetMapping("/getDb2")
    @ResponseBody
    public Blog getDb2()
    {
    	return blogService.selectBlogById(1L);
    }
    
    @GetMapping("/getDb3")
    @ResponseBody
    @Transactional
    public String getDb3()
    {
    	User user = new User();
    	user.setName("杨得朝");
    	user.setBirthday("20210719");
    	user.setPassword("123456");
    	userService.insertUser(user);
        
    	Blog blog = new Blog();
    	blog.setContent("blog");
    	blog.setTitle("blog");
    	blog.setUserId(3);
    	blogService.insertBlog(blog);
    	return "OK";
    }
    
    @GetMapping("/getList")
    @ResponseBody
    public List<Blog> getList()
    {
    	return blogService.selectBlogList(null);
    }
    
    @GetMapping("/getUserList")
    @ResponseBody
    public List<User> getUserList()
    {
    	return userService.selectUserList(null);
    }
}